<?php

/* 用户信息控制器
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require dirname(dirname(__FILE__)) . '/include/init.php';
// 载入 user model
require model('user');
session_start(); //开启session

$action = empty($_GET['action']) ? '' : $_GET['action']; // 接收动作
$uid = $_GET['uid'];
$man_name = $_SESSION['login_name'];
//设置用户权限，只有管理员能够添加、管理用户
if ($man_name == 'admin') {
    if ($action == 'add') {
        $url = 'user.php?action=doadd';
        include WEB_ROOT . '/admin/template/adduser.html.php';
    } elseif ($action == 'doadd') {//处理添加的用户信息
        if (isset($_POST['submit'])) {
            submit_user($_POST['username'], $_POST['password'], $_POST['password1'], $_POST['email']);
        }
    } elseif ($action == 'default') {//显示所有的用户信息
        manuser(); //读取所有的用户信息
        include WEB_ROOT . '/admin/template/manuser.html.php';
    } elseif ($action == 'edit') {
        //获取输入框中的信息，然后放入输入框中
        $uid = $_GET['uid'];
        $userInfo = get_msg($uid); //包含用户相关信息的数组
        $url = 'user.php?action=doedit&uid=' . $uid . '';
        include WEB_ROOT . '/admin/template/adduser.html.php';
    } elseif ($action == 'doedit') {
        $uid = $_GET['uid'];
        //下面方法是处理页面提交的信息   
        if (isset($_POST['submit'])) {
            edit_user($_POST['username'], $_POST['password'], $_POST['password1'], $_POST['email'], $uid);
        }
    } elseif ($action == 'del') {
        confirm_msg('你确定要删除该用户信息吗？', '/admin/user.php?action=dodel&uid=' . $uid . '', '/admin/user.php?action=default');
    } elseif ($action == 'dodel') {
        $uid = $_GET['uid'];
        del_user($uid);
    }
}else{
    
    include WEB_ROOT . '/admin/template/commuser.html.php';
}


